import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;

class MinStack {
    public  Stack<Integer> minstack;
    public  Stack<Integer> stack;

    public MinStack() {
        minstack= new Stack<Integer>();
        stack =new Stack<Integer>();
    }
    
    public void push(int val) {
        stack.push(val);
        if (minstack.isEmpty()){
        minstack.push(val);
    }else{
        if(val<=minstack.peek()){
            minstack.push(val);
        }
    }
    }
    
    public void pop() {
        int x=stack.pop();
        if(!minstack.isEmpty()){
            if(x==minstack.peek()){
                minstack.pop();
            }

        }
       // if(stack.pop()==minstack.peek()){
        //    minstack.pop();

    }
    
    public int top() {
    return stack.peek();
    }
    
    public int getMin() {
        if (!minstack.isEmpty()) {
            return minstack.peek();
        }
        return -1;
    }


}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */